<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">发送任务列表</ui:define>
    <ui:define name="content">
        <h:form id="taskSendForm">

            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>

                        <p:columnToggler datasource="loanPushMessageSendTaskDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         update="@form"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         actionListener="#{loanPushMessageSendTaskBean.onReset}"
                                         process="@this"
                                         update="@form"/>
                        <p:button value="返回" icon="fa fa-reply-all" href="#{currentUserBean.back}"></p:button>
                        <p:button value="创建发送任务" icon="fa fa-reply-all" href="#{loanPushMessageSendTaskBean.onPushMessage()}"></p:button>

                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card ui-g-12">

                            <div class="ui-g-1">
                                <p:outputLabel value="任务名称"/>
                            </div>
                            <div class="ui-g-5">
                                <p:inputText value="#{loanPushMessageSendTaskBean.$.taskName}"/>
                            </div>

                            <div class="ui-g-1">
                                <p:outputLabel value="内容"/>
                            </div>
                            <div class="ui-g-5">
                                <p:inputText value="#{loanPushMessageSendTaskBean.$.content}"/>
                            </div>

                            <div class="ui-g-1">
                                <p:outputLabel value="状态"/>
                            </div>
                            <div class="ui-g-5">
                                <p:selectOneMenu
                                        value="#{loanPushMessageSendTaskBean.$.status}" filter="true"
                                        filterMatchMode="contains">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                                  noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{loanPushMessageSendTaskBean.dictionaries[DictionaryCode.PUSH_MESSAGE_SEND_TASK_STATUS]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>
                            </div>


                            <div class="ui-g-1">
                                <p:outputLabel value="发送时间"/>
                            </div>
                            <div class="ui-g-5">
                                <p:calendar value="#{loanPushMessageSendTaskBean.$.sendTimeMin}"
                                            styleClass="autoWidthCalendar"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"
                                            readonlyInput="true"/>
                                <span>—</span>
                                <p:calendar value="#{loanPushMessageSendTaskBean.$.sendTimeMax}"
                                            styleClass="autoWidthCalendar"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"
                                            readonlyInput="true"/>
                            </div>

                            <div class="ui-g-1">
                                <p:outputLabel value="发送数量"/>
                            </div>
                            <div class="ui-g-5">
                                <p:inputNumber value="#{loanPushMessageSendTaskBean.$.sendCountMin}"
                                               styleClass="autoWidthCalendar"
                                               decimalPlaces="0"/>
                                <span>—</span>
                                <p:inputNumber value="#{loanPushMessageSendTaskBean.$.sendCountMax}"
                                               styleClass="autoWidthCalendar"
                                               decimalPlaces="0"/>
                            </div>

                        </div>


                        <div class="card ui-g-12">
                            <p:dataTable id="loanPushMessageSendTaskDataTable"
                                         style="width: 100%"
                                         var="loanPushMessageSendTask"
                                         value="#{loanPushMessageSendTaskBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection="#{loanPushMessageSendTaskBean.selectedRecords}"
                                         resizableColumns="true">

                                <p:column headerText="操作" width="9%">
                                    <p:splitButton icon="fa fa-eye"
                                                   action="#{loanPushMessageSendTaskBean.onView(loanPushMessageSendTask.id)}"
                                                   process="@this">

                                        <p:menuitem value="取消发送" icon="fa fa-remove"
                                                    action="#{loanPushMessageSendTaskBean.onCancel(loanPushMessageSendTask.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{loanPushMessageSendTask.showCancelButton}">
                                            <p:confirm header="提示信息" message="确定取消?" icon="ui-icon-alert"/>
                                        </p:menuitem>

                                        <p:menuitem value="重新发送" icon="fa fa-repeat"
                                                    actionListener="#{loanPushMessageSendTaskBean.onResend(loanPushMessageSendTask.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{loanPushMessageSendTask.showResendButton}"/>

                                        <p:menuitem value="错误信息" icon="fa fa-warning"
                                                    actionListener="#{loanPushMessageSendTaskBean.onViewError(loanPushMessageSendTask.id)}"
                                                    oncomplete="PF('errorReasonDialogWidgeVar').show();"
                                                    update=":taskSendForm:errorReasonDialog"
                                                    rendered="#{loanPushMessageSendTask.status == 3}"/>

                                    </p:splitButton>
                                </p:column>

                                <p:column headerText="任务ID">
                                    <h:outputText value="#{loanPushMessageSendTask.id}"/>
                                </p:column>

                                <p:column headerText="任务名称">
                                    <h:outputText value="#{loanPushMessageSendTask.taskName}"/>
                                </p:column>

                                <p:column headerText="推送通道">
                                    <h:outputText
                                            value="#{loanPushMessageSendTaskBean.translate(DictionaryCode.PUSH_MESSAGE_CHANNEL,loanPushMessageSendTask.status)}"/>
                                </p:column>

                                <p:column headerText="内容">
                                    <h:outputText value="#{loanPushMessageSendTask.content}"/>
                                </p:column>

                                <p:column headerText="创建时间">
                                    <h:outputText value="#{loanPushMessageSendTask.createTime}"/>
                                </p:column>

                                <p:column headerText="发送时间">
                                    <h:outputText value="#{loanPushMessageSendTask.sendTime}"/>
                                </p:column>

                                <p:column headerText="状态">
                                    <h:outputText
                                            value="#{loanPushMessageSendTaskBean.translate(DictionaryCode.PUSH_MESSAGE_SEND_TASK_STATUS, loanPushMessageSendTask.status)}"/>
                                </p:column>

                                <p:column headerText="完成时间">
                                    <h:outputText value="#{loanPushMessageSendTask.finishTime}"/>
                                </p:column>

                                <p:column headerText="发送数量">
                                    <h:outputText value="#{loanPushMessageSendTask.sendCount}"/>
                                </p:column>

                                <p:column headerText="到达数量">
                                    <h:outputText value="#{loanPushMessageSendTask.arriveCount}"/>
                                </p:column>

                                <p:column headerText="打开数量">
                                    <h:outputText value="#{loanPushMessageSendTask.openCount}"/>
                                </p:column>


                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>

              <p:dialog id="errorReasonDialog" header="任务异常信息" widgetVar="errorReasonDialogWidgeVar"
                      modal="true"
                      resizable="false"
                      closable="true"
                      width="1024"
                      height="400"
                      responsive="true">
                <div class="ui-g ui-fluid">
                    <div class="ui-g-12">
                        <p:inputTextarea rows="20" value="#{loanPushMessageSendTask.errorReason}" readonly="true"/>
                    </div>
                </div>
            </p:dialog>

        </h:form>
    </ui:define>
</ui:composition>
